/*
 * RetaVisualizavel.java
 *
 * Created on 30 de Janeiro de 2007, 00:36
 */

package cefetpb.nav.cartesius.graph;

import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.BasicStroke;
import cefetpb.nav.cartesius.math.Reta;

/**
 *
 * @author Rosberg
 */
public class RetaVisualizavel extends ObjetoGeometricoVisualizavel {
    private Reta reta;
    
    public RetaVisualizavel(String legenda, Reta reta) {
        super(legenda);
        this.reta = reta;
    }
    
    public void desenhar(Graphics2D g, PlaneMeasures pm) {
        double m = -this.reta.getA() / this.reta.getB();
        double n = -this.reta.getC() / this.reta.getB();
        
        double posX;
        double posY;
        double posXAnt = 0.0;
        double posYAnt = 0.0;
        
        for (int pixelX = 0; pixelX < pm.largura; pixelX++) {
            double x = ((double)(pixelX - pm.posicaoEixoVertical)) / pm.unidadeDeMedida;
            double y = m * x + n;
            
            posX = pm.posicaoEixoVertical + x * pm.unidadeDeMedida;
            posY = pm.posicaoEixoHorizontal - y * pm.unidadeDeMedida;
            
            Line2D linha;
            
            if (pixelX == 0) {
                linha = new Line2D.Double(posX, posY, posX, posY);
            } else {
                linha = new Line2D.Double(posXAnt, posYAnt, posX, posY);
            }
            
            g.setStroke(new BasicStroke(1));
            g.draw(linha);
            
            posXAnt = posX;
            posYAnt = posY;
        }
    }
}